<%@ page language="java" import="com.ruohi.manage.*,org.json.*,java.util.*,com.ruohi.util.common.*,java.sql.*,com.ruohi.util.dbutil.*,java.io.File" pageEncoding="UTF-8"%>
<%@page import="java.util.regex.Pattern"%>
<%@page import="java.util.regex.Matcher"%>
<%@page import="com.ruohi.webservice.WEBEmail"%>
<%@page import="org.apache.commons.httpclient.HttpClient"%>
<%@page import="org.apache.commons.httpclient.methods.GetMethod"%>
<%@page import="org.apache.commons.httpclient.params.HttpMethodParams"%>
<%@page import="org.apache.commons.httpclient.DefaultHttpMethodRetryHandler"%>
<%@page import="com.ruohi.spider.HtmlParser"%>
<%@page import="org.apache.commons.io.FileUtils"%>
<%@page import="com.ruohi.util.ReadAndWriteDoc"%>
<%@page import="java.math.BigInteger"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	String flag = CommonString.getFormatPara(request.getParameter("flag"));
	Connection connection = null;
	DBHelper dbHelper = DBHelper.getInstance();
	Map adminInfo = (Map)session.getAttribute("adminInfo");
	String rs = "fail";
	String enumNo = CommonString.getFormatPara(request.getParameter("enumNo"));
	try{
		connection = PoolManager.getConnection(DBType.getDBTypeByEnum(enumNo));
		//登录
		if("login".equals(flag)){
			String usern = CommonString.getFormatPara(request.getParameter("usern"));
			String password = CommonString.getFormatPara(request.getParameter("password"));
			adminInfo = dbHelper.getMap(" select * from "+"service_common_user where usern = ? and password = ? ",new Object [] {usern,password},connection);
			if(null!=adminInfo){
				if(adminInfo.get("state").equals(0)){
					rs = "state0";
				}else{
					session.setAttribute("adminInfo",adminInfo);
					Map postMap = new HashMap();
					postMap.putAll(request.getParameterMap());
					postMap.put("uuid",adminInfo.get("uuid"));
					postMap.put("logFlag","101004");
					//Common.doPostHttpAsync(Common.getDomain(request)+"/backend/action/log.jsp",postMap);
					//修改最后登录信息
					String sql = " UPDATE "+"service_common_user SET login_count = isnull(login_count,0)+1 , last_login_date = '"+CommonDate.getToday("yyyy-MM-dd HH:mm:ss")+"' , last_login_ip = '"+Common.getIp(request)+"' ";
					sql += " WHERE id = ? ";
					dbHelper.execute(sql,new Object [] {adminInfo.get("id")},connection);
					rs = "ok";
				}
			}
		}
		//设置角色权限
		if("set_power".equals(flag)){
			String role_uuid = CommonString.getFormatPara(request.getParameter("role_uuid"));
			String sql = " delete from "+"service_common_role_resource where role_uuid = ? ";
			dbHelper.execute(sql,new Object [] {role_uuid},connection);
			String powerStr = CommonString.getFormatPara(request.getParameter("power"));
			String [] powerArr = powerStr.split(",");
			sql = " INSERT INTO "+"service_common_role_resource ( add_user , add_date , add_ip , uuid , resource_uuid , role_uuid , usern ) ";
			sql += " VALUES ( ? , ? , ? , ? , ? , ? , ? ) ";
			if(null!=powerArr&&powerArr.length>0){
				Object [] [] params  = new Object [powerArr.length] [7];
				for(int i=0;i<powerArr.length;i++){
					params[i][0]=adminInfo.get("usern");
					params[i][1]=CommonDate.getToday("yyyy-MM-dd HH:mm:ss");
					params[i][2]=Common.getIp(request);
					params[i][3]=CommonString.getUUID();
					params[i][4]=powerArr[i].replaceAll("'","");
					params[i][5]=role_uuid;
					params[i][6]="";
				}
				dbHelper.executeBatch(sql,params,connection);
			}
			rs = "ok";
		}
		//设置用户权限
		if("set_power_user".equals(flag)){
			String usern = CommonString.getFormatPara(request.getParameter("usern"));
			String sql = " delete from "+"service_common_role_resource where usern = ? ";
			dbHelper.execute(sql,new Object [] {usern},connection);
			String powerStr = CommonString.getFormatPara(request.getParameter("power"));
			String [] powerArr = powerStr.split(",");
			sql = " INSERT INTO "+"service_common_role_resource ( add_user , add_date , add_ip , uuid , resource_uuid , role_uuid , usern ) ";
			sql += " VALUES ( ? , ? , ? , ? , ? , ? , ? ) ";
			if(null!=powerArr&&powerArr.length>0){
				Object [] [] params  = new Object [powerArr.length] [7];
				for(int i=0;i<powerArr.length;i++){
					params[i][0]=adminInfo.get("usern");
					params[i][1]=CommonDate.getToday("yyyy-MM-dd HH:mm:ss");
					params[i][2]=Common.getIp(request);
					params[i][3]=CommonString.getUUID();
					params[i][4]=powerArr[i].replaceAll("'","");
					params[i][5]="4CCDF227-7F10-4E09-A47C-085CCB4A45FF";
					params[i][6]=usern;
				}
				dbHelper.executeBatch(sql,params,connection);
			}
			rs = "ok";
		}
		if("saveSort".equals(flag)){
			String sortId = CommonString.getFormatPara(request.getParameter("sortId"));
			String tableName = CommonString.getFormatPara(request.getParameter("tableName"));
			String [] idArr =sortId.split(",");
			if(null!=idArr&&idArr.length>0){
				String sql = " update "+tableName+" set order_no = ? where uuid = ? ";
				Object [] [] params = new Object [idArr.length] [2];
				for(int i=0;i<idArr.length;i++){
					params[i][0]=(idArr.length-i);
					params[i][1]=idArr[i];
				}
				dbHelper.executeBatch(sql,params,connection);
			}
			rs = "ok";
		}
		//增加商品时，上传图片的排序
		if(flag.equals("saveSortByAdd")){
			String product_no = CommonString.getFormatPara(request.getParameter("product_no"));
			String sortImg = CommonString.getFormatPara(request.getParameter("sortImg"));
			String tableName = CommonString.getFormatPara(request.getParameter("tableName"));
			String[] imgAry = sortImg.split(",");
			if(imgAry!=null && imgAry.length>0){
				String sql = "update " + tableName + " set order_no=? where parent_id=? and img=?";
				Object[][] paras = new Object[imgAry.length][3];
				for(int i=0;i<imgAry.length;i++){
					paras[i][0] = imgAry.length - i;
					paras[i][1] = product_no;
					paras[i][2] = imgAry[i];
				}
				dbHelper.executeBatch(sql,paras,connection);
			}
			rs = "ok";
		}
		//增加商品时，删除图片
		if(flag.equals("deleteImgByAdd")){
			String product_no = CommonString.getFormatPara(request.getParameter("product_no"));
			String img = CommonString.getFormatPara(request.getParameter("img"));
			String tableName = CommonString.getFormatPara(request.getParameter("tableName"));
			dbHelper.execute("delete from " + tableName + " where parent_id='" + product_no + "' and img='" + img + "'", connection);
			rs = "ok";
		}
		//设置从表中配件图片一张为主图
		if("setMainImg".equals(flag)){
			String imgSrc = CommonString.getFormatPara(request.getParameter("imgSrc"));
			String tableName = CommonString.getFormatPara(request.getParameter("tableName"));
			String parent_id = CommonString.getFormatPara(request.getParameter("parent_id"));
			String sql = " update "+tableName+" set img = '"+imgSrc+"' where no = '"+ parent_id +"'";
			dbHelper.execute(sql,connection);
			rs = "ok";
		}
		if("writeTemplate".equals(flag)){
			String fileName = CommonString.getFormatPara(request.getParameter("fileName"));
			if(!"".equals(fileName)){
				String content = CommonString.getFormatPara(request.getParameter("content"));
				String absolutePath = Common.getAbsolutePath(request);
				File f = new File(absolutePath+"/template/"+fileName);
				FileUtils.writeStringToFile(f,content,"utf-8");
				//更新与模板相关的数据
				List<Map> commonTemplates = dbHelper.getMapList(" select channel_uuid from "+"service_common_template where template_file_name = ? ",new Object [] {fileName},connection);
				List<Map> channels = dbHelper.getMapList(" select no as channel_uuid from "+"service_common_channel where template_file_name = ? ",new Object [] {fileName},connection);
				Map params = null;
				Map channel = null;
				Set<Map> t_s = new HashSet<Map>();
				t_s.addAll(commonTemplates);
				t_s.addAll(channels);
				for(Map m : t_s){
					params = new HashMap();
					params.put("eventAfter", "channelTemplate");
					params.put("channel_uuid", m.get("channel_uuid"));
					Common.doPostHttpAsync(Common.getDomain(request)+"/backend/action/after.jsp", params,request.getCookies());
				}
				rs = "ok";
			}
		}
		//保存设备图片
		if("saveMacImg".equals(flag)){
			String channel_uuid = CommonString.getFormatPara(request.getParameter("channel_uuid"));
			String equipment_id = CommonString.getFormatPara(request.getParameter("equipment_id"));
			String imgStr = CommonString.getFormatPara(request.getParameter("imgStr"));
			JSONArray imgArr = new JSONArray(imgStr);
			JSONObject jsonObject = null;
			String sql = " INSERT INTO "+"used_equipment_image ( add_user , add_date , add_ip , uuid , channel_uuid , equipment_id , original , small , order_no ) ";
			sql += " VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? ) ";
			Object [][] params = new Object [imgArr.length()][9];
			for(int i=0;i<params.length;i++){
				jsonObject = imgArr.getJSONObject(i);
				params[i][0]=adminInfo.get("usern");
				params[i][1]=CommonDate.getToday("yyyy-MM-dd HH:mm:ss");
				params[i][2]=Common.getIp(request);
				params[i][3]=CommonString.getUUID();
				params[i][4]=channel_uuid;
				params[i][5]=equipment_id;
				params[i][6]=jsonObject.getString("url");
				params[i][7]=Common.getSmallImg(jsonObject.getString("url"));
				params[i][8]=0;
			}
			dbHelper.executeBatch(sql,params,connection);
			rs = "ok";
		}
		//多删除
		if("groupDel".equals(flag)){
			String ids = CommonString.getFormatPara(request.getParameter("ids"));
			String tableName = CommonString.getFormatPara(request.getParameter("tableName"));
			String sql = " delete from "+tableName+" where uuid in ("+ ids +")";
			dbHelper.execute(sql,connection);
			rs = "ok";
		}
		//通用修改
		if("commonUpdate".equals(flag)){
			String uuid = CommonString.getFormatPara(request.getParameter("id"));
			String tableName = CommonString.getFormatPara(request.getParameter("tableName"));
			String key =CommonString.getFormatPara(request.getParameter("key"));
			String value = CommonString.getFormatPara(request.getParameter("value"));
			String [] keyArr = key.split(",");
			String sql = " update " + tableName + " set "+key+" = ? where uuid = ? ";
			Object [] params = new Object [keyArr.length+1];
			String [] valArr = value.split(",");
			sql = " update "+tableName+" set ";
			for(int i=0;i<keyArr.length;i++){
				sql += keyArr[i]+" = ? , ";
				params[i]=valArr[i];
			}
			params[keyArr.length]=uuid;
			sql = sql.substring(0,sql.lastIndexOf(",")-1);
			sql += " where uuid = ? ";
			dbHelper.execute(sql,params,connection);
			rs = "ok";
		}
		//删除设备图片
		if("delMacImg".equals(flag)){
			String id = CommonString.getFormatPara(request.getParameter("id"));
			dbHelper.execute(" delete from "+"service_machine_image where uuid = ? ",new Object [] {id},connection);
			rs = "ok";
		}
		
		//保存配件图片
		if("savePartsImg".equals(flag)){
			String channel_uuid = CommonString.getFormatPara(request.getParameter("channel_uuid"));
			String machine_id = CommonString.getFormatPara(request.getParameter("machine_id"));
			String imgStr = CommonString.getFormatPara(request.getParameter("imgStr"));
			JSONArray imgArr = new JSONArray(imgStr);
			JSONObject jsonObject = null;
			String sql = " INSERT INTO "+"service_parts_image ( add_user , add_date , add_ip , uuid , channel_uuid , machine_id , title , img , small_img , order_no , is_show ) ";
			sql += " VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) ";
			Object [][] params = new Object [imgArr.length()][11];
			for(int i=0;i<params.length;i++){
				jsonObject = imgArr.getJSONObject(i);
				params[i][0]=adminInfo.get("usern");
				params[i][1]=CommonDate.getToday("yyyy-MM-dd HH:mm:ss");
				params[i][2]=Common.getIp(request);
				params[i][3]=CommonString.getUUID();
				params[i][4]=channel_uuid;
				params[i][5]=machine_id;
				params[i][6]=jsonObject.getString("title");
				params[i][7]=jsonObject.getString("url");
				params[i][8]=Common.getSmallImg(jsonObject.getString("url"));
				params[i][9]=0;
				params[i][10]=1;
			}
			dbHelper.executeBatch(sql,params,connection);
			rs = "ok";
		}
		//删除配件图片
		if("delPartsImg".equals(flag)){
			String id = CommonString.getFormatPara(request.getParameter("id"));
			dbHelper.execute(" delete from "+"service_parts_image where uuid = ? ",new Object [] {id},connection);
			rs = "ok";
		}
		
		//如果是添加工作分类
		if("addWorkCategory".equals(flag)){
			String sql = " insert into service_work_category ( add_user , add_date , add_ip , uuid , user_uuid , name , order_no ) ";
			sql += " values ( ? , ? , ? , ? , ? , ? , ? ) ";
			String uuid = CommonString.getUUID();
			dbHelper.execute(sql,new Object [] {adminInfo.get("usern"),CommonDate.getToday("yyyy-MM-dd HH:mm:ss"),Common.getIp(request),uuid,adminInfo.get("uuid"),"默认分类",0},connection);
			rs = uuid;
		}
		//删除工作分类
		if("deleteWorkCategory".equals(flag)){
			String id = CommonString.getFormatPara(request.getParameter("id"));
			String sql = " delete from service_work where category_uuid = ? ";
			dbHelper.execute(sql,new Object [] {id},connection);
			sql = " delete from service_work_category where uuid = ? ";
			dbHelper.execute(sql,new Object [] {id},connection);
		}
		//删除工作标签
		if("deleteWork".equals(flag)){
			String id = CommonString.getFormatPara(request.getParameter("id"));
			String sql = " delete from service_work where uuid = ? ";
			dbHelper.execute(sql,new Object [] {id},connection);
		}
		//排序工作标签
		if("sortWork".equals(flag)){
			String ids = CommonString.getFormatPara(request.getParameter("ids"));
			String [] idsArr = ids.split(",");
			for(int i=0;i<idsArr.length;i++){
				dbHelper.execute(" update service_work_category set order_no = ? where uuid = ? ",new Object [] {i,idsArr[i]},connection);
			}
		}
		//统一删除
		if("commonDelete".equals(flag)){
			String id = CommonString.getFormatPara(request.getParameter("id"));
			String tableName = CommonString.getFormatPara(request.getParameter("tableName"));
			dbHelper.execute(" delete from "+tableName+" where id = ? ",new Object [] {id},connection);
		}
		
		if("getMemberUuid".equals(flag)){
			String memberNo = CommonString.getFormatPara(request.getParameter("memberNo")) ;
			Connection sun21_connection = null;
			try{
				sun21_connection = PoolManager.getConnection(DBType.BUSINESS);
				String sel_sql = " select top 1 uuid from gift_member where mem_no = ? " ;
				if(!"".equals(memberNo)){
					out.println(CommonString.getFormatPara(dbHelper.getMap(sel_sql,new Object[]{memberNo},sun21_connection).get("uuid"))) ;
					return;
				}
			}catch(Exception e){
				
			}finally{
				DBHelper.freeConnection(sun21_connection);
			}
		}
		
		
		if(flag.equals("changeShow")){
			String id = CommonString.getFormatPara(request.getParameter("id")) ;
			String show = CommonString.getFormatPara(request.getParameter("show")) ;
			String upt_sql = " update jobs_member_operator set is_show=? where uuid=?" ;
			int result = dbHelper.execute(upt_sql,new Object[]{(1-Integer.parseInt(show)),id},connection) ;
			if(result>0){
				rs = "ok" ;
			}
		}
		//保存商品网从图片
		if("saveSubImg".equals(flag)){
			String channel_uuid = CommonString.getFormatPara(request.getParameter("channel_uuid"));
			String parent_id = CommonString.getFormatPara(request.getParameter("parent_id"));
			String imgStr = CommonString.getFormatPara(request.getParameter("imgStr"));
			String []imgArr = imgStr.split(",");
			String sql = " INSERT INTO gift_sub_image ( add_user , add_date , add_ip , uuid , channel_uuid , parent_id , title , img , small_img , order_no , is_show ) ";
			sql += " VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) ";
			Object [][] params = new Object [imgArr.length][11];
			for(int i=0;i<imgArr.length;i++){
				params[i][0]=adminInfo.get("usern");
				params[i][1]=CommonDate.getToday("yyyy-MM-dd HH:mm:ss");
				params[i][2]=Common.getIp(request);
				params[i][3]=CommonString.getUUID();
				params[i][4]=channel_uuid;
				params[i][5]=parent_id;
				params[i][6]="";
				params[i][7]=imgArr[i];
				params[i][8]=Common.getSmallImg(imgArr[i]);
				params[i][9]=0;
				params[i][10]=1;
			}
			dbHelper.executeBatch(sql,params,connection);
			
			rs = "ok";
		}
		//保存商品网商品参数
		if("saveParamValue".equals(flag)){
			String paramStr = CommonString.getFormatPara(request.getParameter("paramStr"));
			String product_no = CommonString.getFormatPara(request.getParameter("product_no"));
			JSONArray paramArr = new JSONArray(paramStr);
			JSONObject jsonObject = null;
			String sql = " insert into gift_product_param(product_no,no,name,value,type,order_no,is_show,enum_no) values (?,?,?,?,?,?,?,?) ";
			Object [][] params = new Object [paramArr.length()][8];
			for(int i=0;i<params.length;i++){
				jsonObject = paramArr.getJSONObject(i);
				params[i][0]=jsonObject.getString("product_no");
				params[i][1]=jsonObject.getString("no");
				params[i][2]=jsonObject.getString("name");
				params[i][3]=jsonObject.getString("value");
				params[i][4]=jsonObject.getString("type");
				params[i][5]=jsonObject.getString("order_no");
				params[i][6]=1;
				params[i][7]=jsonObject.getString("enum_no");
			}
			dbHelper.execute("delete from gift_product_param where product_no = ?",new Object[]{product_no},connection);//删除该产品原有参数信息
			dbHelper.executeBatch(sql,params,connection);
			rs = "ok";
		}
		//保存商品网商品规格参数
		if("saveParamKeyValue".equals(flag)){
			String paramKeyStr = CommonString.getFormatPara(request.getParameter("paramKeyStr"));
			String product_no = CommonString.getFormatPara(request.getParameter("product_no"));
			//System.out.println(paramKeyStr);
			JSONArray paramKeyArr = new JSONArray(paramKeyStr);
			JSONObject jsonObject = null;
			String sql = " insert into gift_product_param_key(product_no,no,market_price,sale_price,store) values (?,?,?,?,?) ";
			Object [][] params = new Object [paramKeyArr.length()][5];
			for(int i=0;i<params.length;i++){
				jsonObject = paramKeyArr.getJSONObject(i);
				params[i][0]=product_no;
				params[i][1]=jsonObject.getString("no");
				params[i][2]=jsonObject.getString("market_price");
				params[i][3]=jsonObject.getString("sale_price");
				params[i][4]=jsonObject.getString("store");
			}
			dbHelper.execute("delete from gift_product_param_key where product_no = ?",new Object[]{product_no},connection);//删除该产品原有参数信息
			dbHelper.executeBatch(sql,params,connection);
			rs = "ok";
		}
		if("product_saveAgentArea".equals(flag)){
			String agentId = CommonString.getFormatPara(request.getParameter("agentId"));
			String factoryId = CommonString.getFormatPara(request.getParameter("factoryId"));
			String areaIds = CommonString.getFormatPara(request.getParameter("areaIds"));
			dbHelper.execute(" delete from pro_agent_factory_and_area where agent_id = ? and factory_id = ? ",new Object [] {
				agentId,factoryId
			},connection);
			if(!"".equals(areaIds)){
				String [] areaIdArr = areaIds.split(",");
				for(int i=0;i<areaIdArr.length;i++){
					dbHelper.execute(" insert into pro_agent_factory_and_area ( agent_id , factory_id , area_id ) values ( ? , ? , ? ) ",new Object [] {
						agentId,factoryId,areaIdArr[i]
					},connection);
				}
				//删除全部投放广告处
				dbHelper.execute(" delete from pro_agent_ad_area where agent_id = ? and factory_id = ? ",new Object [] {
					agentId,factoryId
				},connection);
				//插入广告投放区域
				for(int i=0;i<areaIdArr.length;i++){
					dbHelper.execute(" insert into pro_agent_ad_area ( agent_id , area_id , factory_id ) values ( ? , ?  , ? ) ",new Object [] {
						agentId,areaIdArr[i],factoryId
					},connection);
				}
			}
			
		}
		
		//商品网类别参数，插入父类别参数
		if("insertParent".equals(flag)){
			String category = CommonString.getFormatPara(request.getParameter("category"));
			String parentCategory = "";
			if(category != null && category.length() >= 6){
				parentCategory = category.substring(0,category.length()-3);
			}
			List paramL = Tools.getCategoryParam(parentCategory,"106013");
					
			String sql = " insert into gift_category_param(add_user,add_date,add_ip,uuid,parent_no,no,name,type,enum_no,is_search,is_key,is_show,order_no) values (?,?,?,?,?,?,?,?,?,?,?,?,?) ";
			Object [][] params = new Object [paramL.size()][13];
			Map m = null;				
			//int maxNo = Integer.parseInt(Tools.getNo(category,"gift_category_param","106013"));
			long maxNo = Long.parseLong(Tools.getNo(category,"gift_category_param","106013"));
			
			 
			for(int i=0;i < paramL.size();i++){
				m = (Map)paramL.get(i);
				params[i][0] = adminInfo.get("usern");
				params[i][1] = CommonDate.getToday("yyyy-MM-dd HH:mm:ss");
				params[i][2] = Common.getIp(request);
				params[i][3] = CommonString.getUUID();
				params[i][4] = category;
				params[i][5] = (maxNo+i)+"";
				params[i][6] = CommonString.getFormatPara(m.get("name"));
				params[i][7] = CommonString.getFormatPara(m.get("type"));
				params[i][8] = CommonString.getFormatPara(m.get("enum_no"));
				params[i][9] = CommonString.getFormatPara(m.get("is_search"));
				params[i][10] = CommonString.getFormatPara(m.get("is_key"));
				params[i][11] = CommonString.getFormatPara(m.get("is_show"));
				params[i][12] = CommonString.getFormatPara(m.get("order_no"));
			}
			
			dbHelper.executeBatch(sql,params,connection);
			rs = "ok";
		}
		
		//新品批量推荐
		if("setRec".equals(flag)){
			String ids = CommonString.getFormatPara(request.getParameter("del_id"));
			String tableName = CommonString.getFormatPara(request.getParameter("tableName"));
			String state = CommonString.getFormatPara(request.getParameter("state"));
			if (null != ids && ids.length() > 0) {// 删除
				String sql = " update " + tableName + " set is_rec = '"+state+"' where uuid in (" + ids
						+ ") ";
				dbHelper.execute(sql,connection);
				rs = "ok";
			}
		}
		
		// 批量显示 20160321
		if("setShow".equals(flag)){
			String ids = CommonString.getFormatPara(request.getParameter("del_id"));
			String state = CommonString.getFormatPara(request.getParameter("state"));
			if (null != ids && ids.length() > 0) {
				String sql = "update gift_product set is_show='"+state+"' where uuid in (" + ids+ ") ";
				rs = dbHelper.execute(sql,connection)+"";
			}
		}
		
		// 批量下架 20160321
		if("setSale".equals(flag)){
			String ids = CommonString.getFormatPara(request.getParameter("del_id"));
			String state = CommonString.getFormatPara(request.getParameter("state"));
			if (null != ids && ids.length() > 0) {
				String sql = "update gift_product set is_buy='"+state+"' where uuid in (" + ids+ ") ";
				rs = dbHelper.execute(sql,connection)+"";
			}
		}
		// 批量可提现 20160401
		if("setPayment".equals(flag)){
			String ids = CommonString.getFormatPara(request.getParameter("del_id"));
			String state = CommonString.getFormatPara(request.getParameter("state"));
			if (null != ids && ids.length() > 0) {
				String sql = "update gift_order set is_partner_payment='"+state+"' where uuid in (" + ids+ ") ";
				rs = dbHelper.execute(sql,connection)+"";
			}
		}
		
		
		//设置/取消商品首页显示
		if(flag.equals("setIndexRec")){
			String ids = CommonString.getFormatPara(request.getParameter("del_id"));
			String tableName = CommonString.getFormatPara(request.getParameter("tableName"));
			int state = CommonString.getFormatInt(request.getParameter("state"));
			if (null != ids && ids.length() > 0) {// 删除
				String sql = "";
				if(state > 0){
					sql = " update " + tableName + " set index_rec_order_no = replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','') where uuid in (" + ids + ") ";
				}else{
					sql = " update " + tableName + " set index_rec_order_no = null where uuid in (" + ids + ") ";
				}
				dbHelper.execute(sql,connection);
				rs = "ok";
			}
		}
		// 新闻审批
		if("upDatePass".equals(flag)){
			String value = CommonString.getFormatPara(request.getParameter("value")) ;
			String uuid = CommonString.getFormatPara(request.getParameter("uuid")) ;
			String upt_sql = "update pro_agent_news set is_approval=? where uuid=?" ;
			if(!"".equals(value) && !"".equals(uuid)){
				dbHelper.execute(upt_sql,new Object[]{value,uuid},connection) ;
			}
		}
		if("update_send_sms_state".equals(flag)){
			String id = CommonString.getFormatPara(request.getParameter("id"));
			dbHelper.execute(" update pro_agent_products_form set is_send_sms = ? where id = ? ",new Object [] {
					1,id
			},connection);
		}
		
		// 供求供应信息导入二手表
		if("importToUsed".equals(flag)){
			connection = PoolManager.getConnection(DBType.getDBTypeByEnum("106008"));
			connection.setAutoCommit(false) ;
			String uid = CommonString.getFormatPara(request.getParameter("uid")) ;
			String sel_sql = "select top 1 * from sell_buy_market where uuid=?" ;
			Map marketMap = null ;
			marketMap = dbHelper.getMap(sel_sql,new Object[]{uid},connection) ;
			if(null!=marketMap && marketMap.size()>0){
				String del_sql = "delete from sell_buy_market where uuid=?" ;
				//  dbHelper.execute(del_sql,new Object[]{uid},connection) ;
				//  connection.commit() ;
				DBHelper.freeConnection(connection); 
				connection = PoolManager.getConnection(DBType.getDBTypeByEnum("106002"));
				String ins_sql = "insert into used_buy(province,mem_no,mem_name,mem_phone,mem_company,title,detail,is_pub,flag,uuid,add_date,order_count,pub_date) values(?,?,?,?,?,?,?,?,?,?,?,?,?) " ;
				Object[] obj = new Object[]{ 
						CommonString.getFormatPara(marketMap.get("province"))+CommonString.getFormatPara(marketMap.get("city")) ,
						CommonString.getFormatPara(marketMap.get("mem_no")) ,
						CommonString.getFormatPara(marketMap.get("mem_name")) ,
						CommonString.getFormatPara(marketMap.get("tel")) ,
						CommonString.getFormatPara(marketMap.get("company")) ,
						CommonString.getFormatPara(marketMap.get("title")) ,
						CommonString.getFormatPara(marketMap.get("descr")) ,
						1,
						1,
						UUID.randomUUID().toString(),
						CommonDate.getToday("yyyy-MM-dd HH:mm:ss") ,
						0,
						CommonDate.getToday("yyyy-MM-dd HH:mm:ss") ,
				} ;
				dbHelper.execute(ins_sql,obj,connection) ;
			} 
			rs = "ok" ;
		}
		// 供求配件信息导入二手表
		if("importToParts".equals(flag)){
			connection = PoolManager.getConnection(DBType.getDBTypeByEnum("106008"));
			connection.setAutoCommit(false) ;
			String uid = CommonString.getFormatPara(request.getParameter("uid")) ;
			String sel_sql = "select top 1 * from sell_buy_market where uuid=?" ;
			Map marketMap = null ;
			marketMap = dbHelper.getMap(sel_sql,new Object[]{uid},connection) ;
			if(null!=marketMap && marketMap.size()>0){
				String del_sql = "delete from sell_buy_market where uuid=?" ;
				//  dbHelper.execute(del_sql,new Object[]{uid},connection) ;
				//  connection.commit() ;
				DBHelper.freeConnection(connection); 
				connection = PoolManager.getConnection(DBType.getDBTypeByEnum("106014"));
				String ins_sql = "insert into part_order(add_user,province,city,mem_no,link_man,tel,product_name,intro,uuid,add_date) values(?,?,?,?,?,?,?,?,?,?) " ;
				Object[] obj = new Object[]{ 
						"market",
						CommonString.getFormatPara(marketMap.get("province")) ,
						CommonString.getFormatPara(marketMap.get("city")),
						CommonString.getFormatPara(marketMap.get("mem_no")) ,
						CommonString.getFormatPara(marketMap.get("mem_name")) ,
						CommonString.getFormatPara(marketMap.get("tel")) ,
						CommonString.getFormatPara(marketMap.get("title")) ,
						CommonString.getFormatPara(marketMap.get("descr")) ,
						UUID.randomUUID().toString(),
						CommonDate.getToday("yyyy-MM-dd HH:mm:ss") ,
				} ;
				dbHelper.execute(ins_sql,obj,connection) ;
			} 
			rs = "ok" ;
		}
	}catch(Exception e){
		e.printStackTrace();
	}finally{
		DBHelper.freeConnection(connection);
	}
	out.print(rs);
%>